/**
 * Created by Jay on 2016/6/13.
 */
function label_classify(){
    sessionStorage.setItem("this_page_click_num","1");
    $("body").off();//先解绑
    var little_id;
    var  url,method,data

    $("body").on("click",".rep_search_lab",function(){
        var this_click_num=sessionStorage.setItem("this_page_click_num",1);
        var val=$(".rep_search_real_lab").val();
        if(val==""){
            url="labelManageController/getAllLabelCategory";
            method="get";
            data={pageSize: 10, pageNo:1};
        }else{
            url="labelManageController/vagueSearchLabel";
            method="POST";
            data= {labelName:$(".rep_search_real_lab").val(),pageSize:10,pageNo:1};

        }
        $.ajax({
                url:url,
                method:method,
                data:data
        })
        .done(function(data){
            page_i=0;
            //console.log(data);
            if(val!=""){
                data.result=data.result.resultList;
            }
            two_ww(data);
        })
    })
    $("body").on("click",".delete_label",function(){
        $.ajax({
            url: "abelManageController/delLabel",
            method: "get",
            data: {labelId:$(this).attr("data-lid")}
        })
        .done(function(){
                layer.alert("删除成功")
        })
    })
    //labelManageController/vagueSearchLabel
    mccmsa.ajax({
        url: "labelManageController/getAllLabelCategory",
        method: "get",
        data: {pageSize: 10, pageNo:1},
        //sessionStorage.getItem("this_page_click_num")
        success:function(data){
            //console.log(data);
            two_ww(data);
        }
    })
    /*抽出来*/
    function two_ww(data){
        var return_data=1*data.result.pageNo;//返回的首位数
        sessionStorage.setItem("pageNo",data.result.pageNo);
        sessionStorage.setItem("pageSize",data.result.pageSize);
        sessionStorage.setItem("return_data",return_data);
        set_seqsum(
            {
                pageNo:data.result.pageNo,
                pageSize:data.result.pageSize
            }
        );
        //console.log(data);
        mccmsa.getHtmlFromLocalTemplate({   //将数据打包到模版丢进容器
            templateId: "getColumnTableData_lab",
            container: $("#ColumnTableData_lab"),
            data: data,
            callback:function(){
                $("body").on("click",".get_lab",function(){
                    var x=$(this).attr("data-lid");
                    mccmsa.goTo("little_label_classify","label_classify",{x:x});
                })
                $("body").on("click",".little_l",function(){
                    little_id=$(this).attr("data-lid");//保存id
                    //alert("ll:"+little_id);
                })
                $("body").on("click",".lab_click",function(e){
                    e.stopPropagation();
                    if(little_id=="undefined")return;//可能为空。。
                    var input_val=$("#little_lab").val();
                    mccmsa.ajax({
                        url:"labelManageController/addLabel",
                        method:"post",
                        data:{labelCategoryId:little_id,labelName:input_val},
                        success: function (data) {
                            //console.log(data);
                            if(!data.status==200) return;
                            layer.alert("添加成功");
                        },
                        error:function(){
                            layer.alert("没哟成功");
                        }
                    })
                })//添加小标签
            }
        })
    }
}